package com.housekeeper.maili.housekeeper.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2016/12/10.
 */

public abstract class BaseFragment extends Fragment implements View.OnClickListener {
    public Activity context;

    /**
     * 是否将root附加到布局文件的根视图上
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        context = getActivity();
        View view = initView(inflater, container);
        initdata();
        return view;
    }

    /**
     * 初始化view
     */
    public abstract View initView(LayoutInflater inflater, ViewGroup container);

    /**
     * 初始化数据
     */
    public abstract void initdata();

    /**
     * 获取视图
     */
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            default:
                onClickListener(view);
                break;
        }
    }

    /**
     * 重写点击事件，重写时删除suoer；
     */
    protected void onClickListener(View view) {
        throw new UnsupportedOperationException("请重写onClickListener(View view)");
    }
}
